{% extends "base_generic.html" %}

{% block content %}

  {% if form.errors %}
    <div class="alert alert-danger">
      <p>用户名或密码不正确，请重试。</p>
    </div>
  {% endif %}

  {% if next %}
    {% if user.is_authenticated %}
      <div class="alert alert-info">
        <p>您的账号没有权限访问该页面。请使用具有相应权限的账号登录。</p>
      </div>
    {% else %}
      <div class="alert alert-info">
        <p>请登录后继续访问。</p>
      </div>
    {% endif %}
  {% endif %}

  <div class="card">
    <div class="card-header bg-primary text-white">
      <h4 class="mb-0"><i class="fas fa-sign-in-alt me-2"></i>登录</h4>
    </div>
    <div class="card-body">
      <form method="post" action="{% url 'login' %}">
        {% csrf_token %}
        <div class="mb-3">
          <label for="id_username" class="form-label">用户名</label>
          <input type="text" name="username" id="id_username" class="form-control" required>
        </div>
        <div class="mb-3">
          <label for="id_password" class="form-label">密码</label>
          <input type="password" name="password" id="id_password" class="form-control" required>
        </div>
        <div class="d-grid gap-2">
          <button type="submit" class="btn btn-primary">登录</button>
        </div>
        <input type="hidden" name="next" value="{{ next }}">
      </form>
      
      <div class="mt-3">
        <p><a href="{% url 'password_reset' %}">忘记密码?</a></p>
        <p>还没有账号？<a href="{% url 'register' %}">立即注册</a></p>
      </div>
    </div>
  </div>

{% endblock %} 